package eu.pago.chat.gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.Registry;
import java.util.List;

import javax.swing.JFrame;

import commonServer.IServer;

class ClickButton implements ActionListener {

	LoginFrame frame;
	Registry registry;

	public ClickButton(LoginFrame frame, Registry registry) {
		this.registry = registry;
		this.frame = frame;
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		IServer serverCentral;
		List<InfoFriend> friends = null;
		try {
			//
			// try {
			// registry = LocateRegistry.createRegistry(CommonServer.PORT);
			// } catch (RemoteException exc) {
			// registry = LocateRegistry.getRegistry(CommonServer.PORT);
			// }

			serverCentral = (IServer) registry.lookup("Server");
			friends = serverCentral.signIn(frame.userTextField.getText());

		} catch (RemoteException | NotBoundException exc) {
			// TODO Auto-generated catch block
			exc.printStackTrace();
		}

		@SuppressWarnings("unused")
		JFrame friendsFrame = new FriendsFrame(friends);
		frame.dispose();
	}
}